package it.lorenz.server.fk.services;

import it.lorenz.server.fk.business.AbstractDTO;
import it.lorenz.server.fk.business.BusinessManager;
import it.lorenz.server.fk.business.IBusinessProcess;
import it.lorenz.server.fk.business.ex.AbstractBusinessException;
import it.lorenz.server.fk.business.ex.ValidationException;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class AbstractService implements ApplicationContextAware {

    private ApplicationContext springContext;
    @Autowired
    private BusinessManager businessManager;

    protected AbstractDTO executeBusinessProcess(String businessProcessName,
       AbstractDTO dto) throws SecurityException, ValidationException,
       AbstractBusinessException {
        IBusinessProcess businessProcess = (IBusinessProcess) springContext
           .getBean(businessProcessName);
        return businessManager.executeBusinessProcess(dto, businessProcess);
    }

    public void setBusinessManager(BusinessManager businessManager) {
        this.businessManager = businessManager;
    }

    protected ApplicationContext getSpringContext() {
        return springContext;
    }

    @Override
    public void setApplicationContext(ApplicationContext springContext) throws BeansException {
        this.springContext = springContext;
    }
}
